/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaPC.java
 *
 * Created on 05/08/2011, 17:28:19
 */
package tsb.UI.Ventanas;

import tsb.dominio.interfaces.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import tsb.UI.Ventanas.VentanaDeError;
import tsb.dominio.enumeraciones.AsignacionIP;
import tsb.dominio.dispositivos.hostfinal.PC;

/**
 *
 * @author Fede
 */
public final class VentanaPC extends javax.swing.JFrame {
    
    private PC pc;
    private ArrayList<InterfaceDeConeccion> listaInterfaces;

    /** Creates new form VentanaPC */
    public VentanaPC(String nombreAMostrar) {
        initComponents();
        
        listaInterfaces = new ArrayList<InterfaceDeConeccion>();
        
        tsb.gestores.GestorDePC gestorPC = new tsb.gestores.GestorDePC();
        PC pc1=gestorPC.getPC("PC-1");
       
        this.setPC(pc1);
        
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelPC = new tsb.UI.Paneles.PanelPC();
        panelBotones = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PC");
        setBackground(new java.awt.Color(255, 51, 102));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        panelBotones.setBackground(new java.awt.Color(255, 255, 255));

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(266, Short.MAX_VALUE)
                .addComponent(btnAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar)
                .addContainerGap())
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnAceptar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelPC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelPC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        
         PC pc= this.getPC();
         tsb.gestores.GestorDePC gestorPC = new tsb.gestores.GestorDePC();
         if(gestorPC.editarPC(pc))
         {
             System.out.println("se actualizo la pc");
         }
         else
         {
             System.out.println("No se actualizo");
         }
        
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
    this.panelPC.getInterfaz1();        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JPanel panelBotones;
    private tsb.UI.Paneles.PanelPC panelPC;
    // End of variables declaration//GEN-END:variables

    public void setPC(PC pc)
    {
        this.pc=pc;
        this.panelPC.setNombreAMostrar(pc.getNombreAMostrar());
        this.panelPC.setEncendido(pc.getEstado());
        if(pc.getDHCP_Static()!=null)
        {
            this.panelPC.setAsignacionIP(pc.getDHCP_Static());
        }
        this.panelPC.setGateway(pc.getGateway());
        this.panelPC.setServidorDNS(pc.getServidorDNS());
    }
    
    public PC getPC()
    {
        this.pc.setNombreAMostrar(this.panelPC.getNombreAMostrar());
        this.pc.setEstado(this.panelPC.getEncendido());
        this.pc.setDHCP_Static(this.panelPC.getAsignacionIP());
        this.pc.setGateway(this.panelPC.getServdorDNS());
        this.pc.setGateway(this.panelPC.getGateway());
        this.pc.setServidorDNS(this.panelPC.getServdorDNS());
        
        this.listaInterfaces.add(this.panelPC.getInterfaz1());
        this.listaInterfaces.add(this.panelPC.getInterfaz2());
        
        this.pc.setInterfaces(listaInterfaces);
        
        return pc;
        
    }
}
